package d4_collection_set;

import java.util.HashSet;
import java.util.Set;

/**
 * 2024/6/5 HashSet去重  Cjj  8:12
 */
public class SetTest3 {
    public static void main(String[] args) {

        /**在HashSet中，如果有两个内容是重复的,想要去重 必须重写对象的 equals()方法 和 haseCode()方法 ,才能去重**/


        Set<Student> students = new HashSet<>();
        Student s1 = new Student("孙悟空",20,1.67);
        Student s2 = new Student("孙悟空",20,1.67);
        Student s3 = new Student("猪八戒",21,1.97);
        Student s4 = new Student("唐僧",32,1.87);

        students.add(s1);
        students.add(s2);
        students.add(s3);
        students.add(s4);
        System.out.println(students);
    }
}
